package com.example.base.job;

import com.example.base.utils.SpringContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

@Slf4j
public class AppJob extends QuartzJobBean {

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDetail jobDetail=jobExecutionContext.getJobDetail();
        JobDataMap jobDataMap=jobDetail.getJobDataMap();
        JobModel job =(JobModel) jobDataMap.get("sysjob");
        try {
            AppJobModelService jobModelService= SpringContextUtils.getBean(AppJobModelService.class);
            log.info("开始执行了 {}",job.getAppClass());
            jobModelService.appJobExecute(job);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
